import type { ConsultOrderItem } from "@/types/consult";
import { ref } from "vue";
import { canCelOrderApi,deleteOrderApi } from "@/services/consult";
import { showToast } from "vant";
import { OrderType } from "@/enums";
// 取消订单
export const useOrderCanCel = () => {
  const loading1 = ref(false);
  const cancelConsultOrder = async (item: ConsultOrderItem) => {
    try {
      loading1.value = true;
      await canCelOrderApi(item.id);
      item.status = OrderType.ConsultCancel;
      item.statusValue = "已取消";
      showToast("取消成功");
    } catch (error) {
      showToast("取消失败");
    } finally {
      loading1.value = false;
    }
  };
  return { loading1, cancelConsultOrder };
};


// 删除订单
export const useDeleteOrder = (cb: () => void) => {
  const loading2= ref(false)
  const deleteConsultOrder = async (item: ConsultOrderItem) => {
    try {
      loading2.value = true
      await deleteOrderApi(item.id)
      showToast('删除成功')
      cb && cb()
    } catch (error) {
      showToast('删除失败')
    } finally {
      loading2.value = false
    }
  }
  return { loading2, deleteConsultOrder }
}